import * as types from '../mutation-types';
import { fetch } from 'utils/api.js';

const state = {
  totalCommentCount:0,
  commentList: []
};

const mutations = {
};

const actions = {
  loadCommentList({ commit, state },{targetId,status,page,size}) {
    return new Promise((resolve, reject) => {
      fetch('commentList',{ body: { targetId: targetId,status:status,page:page,size:size } }).then((res) => {
        if (res.code === 200) {
          resolve(res.data);
        } else {
          throw new Error('Response Error');
          reject();
        }
      });
    });
  },
  submitCommentIds({ commit, state },{targetId,ids,tag}) {
    if(ids.length < 1 ){
      alert("请选择跟帖");
      return ;
    }
    return new Promise((resolve, reject) => {
      fetch('showOrHideComment',{ body: { contentId: targetId,tag:tag },url:{ids:ids} }).then((res) => {
        if (res.code === 200) {
          alert('操作成功');
          resolve(res.data);
        } else {
          alert(res.message);
          reject();
        }
      });
    });
  }
};

export default {
  state,
  mutations,
  actions
};
